//
// Copyright (c) 2011, Peter Lane
// Licensed under the Academic Free License version 3.0

package fan.swtChartWrapper;

import fan.sys.*;
import org.eclipse.swt.SWT;

/**
 * Collection of common methods, needed by different peers.
 * 
 */
public class Utility {
  /**
   * Overloaded 'toSwt' method: version to convert linestyles
   */
  static org.eclipse.swtchart.LineStyle toSwt (LineStyle linestyle) {
    if (linestyle == LineStyle.dash) {
      return org.eclipse.swtchart.LineStyle.DASH;
    } else if (linestyle == LineStyle.dash_dot) {
      return org.eclipse.swtchart.LineStyle.DASHDOT;
    } else if (linestyle == LineStyle.dash_dot_dot) {
      return org.eclipse.swtchart.LineStyle.DASHDOTDOT;
    } else if (linestyle == LineStyle.dot) {
      return org.eclipse.swtchart.LineStyle.DOT;
    } else if (linestyle == LineStyle.none) {
      return org.eclipse.swtchart.LineStyle.NONE;
    } else { // if (linestyle == LineStyle.solid) 
      return org.eclipse.swtchart.LineStyle.SOLID;
    }
  }

  /**
   * Overloaded 'toSwt' method: version to convert errorbartypes.
   */
  static org.eclipse.swtchart.IErrorBar.ErrorBarType toSwt (fan.swtChartWrapper.ErrorBarType type) {
    if (type == fan.swtChartWrapper.ErrorBarType.both)
      return org.eclipse.swtchart.IErrorBar.ErrorBarType.BOTH;
    else if (type == fan.swtChartWrapper.ErrorBarType.minus)
      return org.eclipse.swtchart.IErrorBar.ErrorBarType.MINUS;
    else // if (type == ErrorBarType.plus)
      return org.eclipse.swtchart.IErrorBar.ErrorBarType.PLUS;
  }

  /**
   * Overloaded 'toSwt' method: version to convert position.
   */
  static int toSwt (Position position) {
    if (position == Position.left) {
      return SWT.LEFT;
    } else if (position == Position.right) {
      return SWT.RIGHT;
    } else if (position == Position.top) {
      return SWT.TOP;
    } else { // if (position == Position.bottom) {
      return SWT.BOTTOM;
    }
  }

  /**
   * Overloaded 'toSwt' method: version to convert plotsymboltype.
   */
  static org.eclipse.swtchart.ILineSeries.PlotSymbolType toSwt (PlotSymbolType symbolType) {
    if (symbolType == PlotSymbolType.circle)
      return org.eclipse.swtchart.ILineSeries.PlotSymbolType.CIRCLE;
    else if (symbolType == PlotSymbolType.square)
      return org.eclipse.swtchart.ILineSeries.PlotSymbolType.SQUARE;
    else if (symbolType == PlotSymbolType.diamond)
      return org.eclipse.swtchart.ILineSeries.PlotSymbolType.DIAMOND;
    else if (symbolType == PlotSymbolType.triangle)
      return org.eclipse.swtchart.ILineSeries.PlotSymbolType.TRIANGLE;
    else if (symbolType == PlotSymbolType.inverted_triangle)
      return org.eclipse.swtchart.ILineSeries.PlotSymbolType.INVERTED_TRIANGLE;
    else if (symbolType == PlotSymbolType.cross)
      return org.eclipse.swtchart.ILineSeries.PlotSymbolType.CROSS;
    else if (symbolType == PlotSymbolType.plus)
      return org.eclipse.swtchart.ILineSeries.PlotSymbolType.PLUS;
    else // if (symbolType == PlotSymbolType.none)
      return org.eclipse.swtchart.ILineSeries.PlotSymbolType.NONE;
  }

  /**
   *
   */
  static int toSwt (ImageType format) {
    if (format == ImageType.bmp_rle)
      return SWT.IMAGE_BMP_RLE;
    else if (format == ImageType.bmp)
      return SWT.IMAGE_BMP;
    else if (format == ImageType.jpeg)
      return SWT.IMAGE_JPEG;
    else if (format == ImageType.ico)
      return SWT.IMAGE_ICO;
    else if (format == ImageType.gif)
      return SWT.IMAGE_GIF;
    else if (format == ImageType.tiff)
      return SWT.IMAGE_TIFF;
    else // if (format == ImageType.png)
      return SWT.IMAGE_PNG;
  }

  /**
   * Convert a List to a String[].
   */
  static String[] toStringArray (List items) {
    String[] result = new String[(int)items.size ()];
    for (int i = 0; i < items.size (); i++) {
      result[i] = (String)items.get(i);
    }
    return result;
  }

  /**
   * Convert a List to a double[].
   */
  static double[] toDoubleArray (List items) {
    double[] result = new double[(int)items.size()];

    for (int i = 0; i < result.length; i++) {
      result[i] = ((Double)items.get(i)).doubleValue();
    }
    return result;
  }
}
